package com.itheima.spring.bestpractive.utils;

import com.itheima.spring.bestpractive.mapping.AssessmentMapping;
import com.itheima.spring.bestpractive.pojo.AssessmentIndicator;
import com.itheima.spring.bestpractive.pojo.AssessmentPlan;
import com.itheima.spring.bestpractive.pojo.EmployeeIndicatorScore;
import com.itheima.spring.bestpractive.service.AssessmentService;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * @version 1.0
 * @author: HZY
 * @date: 2025/6/25 16:46
 * @Content: 考核结果计算
 */
@Component
public class  AssessmentCalculate {
    @Autowired
    private  AssessmentMapping assessmentMapping;
    @Operation(description = "计算考核结果")
    public  BigDecimal calculateScore(List<EmployeeIndicatorScore> scores) {
        List<Long> indicatorIds = scores.stream().map(EmployeeIndicatorScore::getIndicatorId).toList();
        List<BigDecimal> bigDecimals = assessmentMapping.selectIndicatorWeight(indicatorIds);
        BigDecimal sum = scores.stream().map(score -> score.getScore().multiply(bigDecimals.get(scores.indexOf(score)))).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        return sum.multiply(new BigDecimal("0.01"));
    }
}
